<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>加载不同的广告</title>
</head>
<body>
<script>
    var ads = [
        'Buy Product A! You won\' be sorry!',
        'You need Product B! Buy buy buy!',
        'Don\'t buy Product A or B! Product C is the only option for you!'
    ];

    var lastAdNumber = localStorage.getItem('lastAdNumber');
    var nextNumber = getRandomNumber(0, ads.length);
    if (!lastAdNumber) {
        lastAdNumber = nextNumber;
    } else {
        lastAdNumber = parseInt(lastAdNumber, 10);
        while (lastAdNumber == nextNumber) {
            nextNumber = getRandomNumber(0, ads.length);
        }
    }

    localStorage.setItem('lastAdNumber', nextNumber);
    document.write(ads[nextNumber]);

    function getRandomNumber(min, max) {
        return Math.floor((Math.random() * max) + min);
    }
</script>
</body>
</html>